package com.company.笔试.压缩字符串;

import java.util.*;

public class Main{
    public static void main(String args[]){
        String str  = "bbDQQQQQ";
        String res = new String();
        HashMap<Character,Integer> map = new HashMap<>();
        char lastch = ' ';
        for(char ch : str.toCharArray()){
            if(map.containsKey(ch)){
                
                map.put(ch,map.get(ch)+1);
            }else if(map.size()>0){
                String tmp = ""+lastch+""+map.get(lastch)+"";
                res += tmp;
                map = new HashMap<>();
                map.put(ch,1);
                lastch = ch;
            }else {
                lastch = ch;
                map.put(ch,1);
            }
            
        }
        if (map.size()>0){
            String tmp = ""+lastch+""+map.get(lastch)+"";
            res += tmp;
        }
        System.out.print(res);
    }

}